package com.corpgovernment.swagger;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2 // 启动 Swagger2
public class SwaggerConfig {
    @Bean // 构建并配置 Docket 对象
    // 注：这里注入了 Environment 对象，目的是获取系统环境
    public Docket docket(Environment environment) {

    // 判断当前是否处于该环境

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .enable(true)
                .useDefaultResponseMessages(false)
                .select() // 返回 ApiSelectorBuilder
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 接口扫描方案，多个controller包可以用Predicates.or()连接
                .paths(PathSelectors.any()) // 接口路径过滤方案
                .build();
    }

    // 构建基本配置信息
    public ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("organization-manage")
                .description("organization-manage的接口文档")
                .version("v1.0")
                .contact(new Contact("携程程曦", "", ""))
                .build();
    }
}
